package com.smart_campus.campus.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.campus.vo.CampusJournalismVo;
import com.smart_campus.sys.common.DataGridView;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.campus.domain.CampusJournalism;
import com.smart_campus.campus.mapper.CampusJournalismMapper;
import com.smart_campus.campus.service.CampusJournalismService;

import java.util.List;
import java.util.Map;

/**
 * @author Alfred
 * @time: 2020/6/28 19:26
 * 
 */
@Service
public class CampusJournalismServiceImpl implements CampusJournalismService{

    @Resource
    private CampusJournalismMapper campusJournalismMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.campus.service.impl.CampusJournalismServiceImpl",key = "#id")
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return campusJournalismMapper.deleteByPrimaryKey(id);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CampusJournalismServiceImpl",key = "#result.id")
    @Override
    public CampusJournalism insert(CampusJournalism record) {
        campusJournalismMapper.insert(record);
        return record;

    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CampusJournalismServiceImpl",key = "#result.id")
    @Override
    public CampusJournalism insertSelective(CampusJournalism record) {
        campusJournalismMapper.insertSelective(record);
        return record;
    }

    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
    @Cacheable(cacheNames ="com.smart_campus.campus.service.impl.CampusJournalismServiceImpl",key = "#id")
    @Override
    public CampusJournalism selectByPrimaryKey(Integer id) {
        return campusJournalismMapper.selectByPrimaryKey(id);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CampusJournalismServiceImpl",key = "#result.id")
    @Override
    public CampusJournalism updateByPrimaryKeySelective(CampusJournalism record) {
        campusJournalismMapper.updateByPrimaryKeySelective(record);
        return record;

    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.CampusJournalismServiceImpl",key = "#result.id")
    @Override
    public CampusJournalism updateByPrimaryKey(CampusJournalism record) {
        campusJournalismMapper.updateByPrimaryKey(record);
        return record;

    }

    @Override
    public DataGridView queryJournalism(CampusJournalismVo campusJournalismVo) {
        Page<Object>page= PageHelper.startPage(campusJournalismVo.getPage(),campusJournalismVo.getLimit());
        List<Map> campusJournalismVos = this.campusJournalismMapper.queryJournalism(campusJournalismVo);
        return new DataGridView(page.getTotal(),campusJournalismVos);
    }

    @Override
    public Integer queryMax() {
        return this.campusJournalismMapper.queryMax();
    }

    @Override
    public Integer queryMaxId() {
        return this.campusJournalismMapper.queryMaxId();
    }

}
